#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project  : ecshop
# @File     : page_backend_add_luckymoney.py
# @Author   : WanLiWei
# @Time     : 2021/7/3 11:00
from time import sleep
from selenium.webdriver.common.by import By
class PageBackendAddLuckymoney():
    """添加红包"""
    def __init__(self,driver):
        self.driver=driver
    def test_click_promotion(self):
        # 进入id为menu-frame的frame
        self.driver.switch_to.frame('menu-frame')
        # 点击促销管理
        self.driver.find_element_by_xpath('//ul[@id="menu-ul"]/li[2]').click()
    def test_click_luckymoney(self):
        # 点击红包类型
        self.driver.find_element_by_xpath('//ul[@id="menu-ul"]/li[2]/ul/li[2]/a').click()
        # 退出frame
        self.driver.switch_to.default_content()
    def test_input_name(self):
        # 进入id为main-frame的frame
        self.driver.switch_to.frame('main-frame')
        self.driver.find_element_by_xpath('/html/body/h1/span[1]/a').click()
        # 类型名称
        self.driver.find_element(By.NAME, 'type_name').send_keys("红包来了吗")
    def test_input_money(self):
        # 红包金额
        self.driver.find_element(By.NAME, 'type_money').send_keys(100)
    def test_input_min_money(self):
        # 最小订单金额
        self.driver.find_element(By.ID, 'min_goods_amount').send_keys(100)
    def test_click_lucky_type(self):
        # 如何发放此类型红包
        sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[1]/form/table/tbody/tr[4]/td[2]/input[2]').click()
    def test_start_data(self):
        # 发放起始日期
        # 删除元素中属性的方法--日期处理
        # 开始日期
        js = "document.getElementById('send_start_date').removeAttribute('ReadOnly')"
        self.driver.execute_script(js)
        self.driver.find_element_by_id("send_start_date").clear()
        self.driver.find_element_by_id("send_start_date").send_keys("2021-08-14")
    def test_end_data(self):
        # 发放结束日期
        js = "document.getElementById('send_end_date').removeAttribute('ReadOnly')"
        self.driver.execute_script(js)
        self.driver.find_element_by_id("send_end_date").clear()
        self.driver.find_element_by_id("send_end_date").send_keys("2021-10-22")
    def test_use_start_data(self):
        # 使用起始日期
        js = "document.getElementById('use_start_date').removeAttribute('ReadOnly')"
        self.driver.execute_script(js)
        self.driver.find_element_by_id("use_start_date").clear()
        self.driver.find_element_by_id("use_start_date").send_keys("2022-11-11")
    def test_use_end_data(self):
        # 使用结束日期
        js = "document.getElementById('use_end_date').removeAttribute('ReadOnly')"
        self.driver.execute_script(js)
        self.driver.find_element_by_id("use_end_date").clear()
        self.driver.find_element_by_id("use_end_date").send_keys("2022-12-22")
    def test_click_confirm(self):
        # 确定按钮
        self.driver.find_element_by_xpath('/html/body/div[1]/form/table/tbody/tr[10]/td[2]/input[1]').click()
        # 退出frame
        self.driver.switch_to.default_content()
    def test_add_lucky_money(self):
        self.test_click_promotion()
        self.test_click_luckymoney()
        self.test_input_name()
        self.test_input_money()
        self.test_input_min_money()
        self.test_click_lucky_type()
        self.test_start_data()
        self.test_end_data()
        self.test_use_start_data()
        self.test_use_end_data()
        self.test_click_confirm()

